package net.linlan.plat.comm.aspect;

import net.linlan.commons.core.CoreException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;


/**
 * the class of redis aspect
 * Filename:RedisAspect.java
 * Desc: the redis aspect class
 * 通过配置文件内的开启状态，执行是否需要保存到Redis服务器的操作
 *
 * @author Linlan
 * CreateTime:2017/10/25 20:01
 *
 * @version 1.0
 * @since 1.0
 *
 */
@Aspect
@Configuration
public class RedisAspect {
    private Logger logger = LoggerFactory.getLogger(getClass());
    //是否开启redis缓存  true开启   false关闭
    @Value("${platform.redis.open}")
    private boolean open;

    @Around("execution(* net.linlan.sys.web.RedisService.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object result = null;
        if(open){
            try{
                result = point.proceed();
                //System.out.println("-------redis aspect-------");

            }catch (Exception e){
                logger.error("redis error", e);
                throw new CoreException("Redis服务异常");
            }
        }
        return result;
    }


}

